<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="org.hibernate.*,web.study.hibernate.entity.*,web.study.hibernate.util.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>add user information</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->

</head>

<body>
	<%
	    if (request.getParameter("id") != null)
	    {
	        int id = Integer.parseInt(request.getParameter("id"));
	        String name = request.getParameter("name");
	        String password = request.getParameter("password");
	        String department = request.getParameter("department");
	        int age = Integer.parseInt(request.getParameter("age"));
	        try
	        {
	            Transaction tx = null;
	            UserInfo user = new UserInfo();
	            user.setId(id);
	            user.setPassword(password);
	            user.setName(name);
	            user.setDepartment(department);
	            user.setAge(age);
	            Session Hsession = HibernateUtil.currentSession();
	            tx = Hsession.beginTransaction();
	            Hsession.save(user);
	            tx.commit();
	            HibernateUtil.closeSession();
	        }
	        catch (Exception e)
	        {
	            System.out.println("添加失败" + e);
	        }
	    }
	%>
	<center>
		<form action="addUserInfo.jsp" method="post" name="form1"
			target="_self">
			<p>
				I&nbsp;&nbsp;D： <input name="id" type="text" id="id" />
			</p>
			<p>
				姓名：<input name="name" type="text" id="name" />
			</p>
			<p>
				密码：<input name="password" type="password" id="password" />
			</p>
			<p>
				部门：<input name="department" type="text" id="department" />
			</p>
			<p>
				年龄：<input type="text" name="age" id="age" />
			</p>
			<p>
				<input type="submit" name="submit" value="提交" />
			</p>
		</form>
	</center>
</body>
</html>